﻿@inherits SettingsBase

<ConditionComponent AuthKey="saveTitle">
    <div class="card">
        <div class="card-header">系统名称设置</div>
        <div class="card-body">
            <ConditionComponent>
                <div class="alert alert-danger" role="alert">
                    <span>演示系统禁止更改系统名称</span>
                </div>
            </ConditionComponent>
            <div class="form-group">
                <div class="input-group">
                    <input type="text" class="form-control" placeholder="请输入网站标题，50字以内" @bind-value="@Model.Title" />
                    <ConditionComponent Inverse="true">
                        <div class="input-group-append">
                            <button class="btn btn-secondary" type="button" @onclick="SaveWebTitle">保存</button>
                        </div>
                    </ConditionComponent>
                </div>
            </div>
        </div>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="saveFooter">
    <div class="card">
        <div class="card-header">网站页脚设置</div>
        <div class="card-body">
            <ConditionComponent>
                <div class="alert alert-danger" role="alert">
                    <span>演示系统禁止更改网站页脚</span>
                </div>
            </ConditionComponent>
            <div class="form-group">
                <div class="input-group">
                    <input type="text" class="form-control" id="sysFoot" placeholder="请输入网站页脚，50字以内" @bind-value="@Model.Footer" />
                    <ConditionComponent Inverse="true">
                        <div class="input-group-append">
                            <button class="btn btn-secondary" type="button" @onclick="SaveWebFooter">保存</button>
                        </div>
                    </ConditionComponent>
                </div>
            </div>
        </div>
    </div>
</ConditionComponent>
<div class="card">
    <div class="card-header"><label class="control-label" data-toggle="lgbinfo" data-content="通过此功能进行整个网站的登录界面设置">后台管理登录地址设置</label></div>
    <div class="card-body">
        <div class="form-group">
            <div class="form-group text-right">
                <div class="btn-group" role="group">
                    <Dropdown @bind-Value="@Model.SelectedLogin" Items="@Model.Logins"></Dropdown>
                    <button class="btn btn-secondary" type="button">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="card">
    <div class="card-header"><label class="control-label" data-toggle="lgbinfo" data-content="此功能给前台网站拼接后台功能菜单时使用">后台管理地址设置</label></div>
    <div class="card-body" data-toggle="LgbValidate" data-valid-button="[data-method='appPath']">
        <ConditionComponent>
            <div class="alert alert-danger" role="alert">
                <span>演示系统禁止更改后台管理地址</span>
            </div>
        </ConditionComponent>
        <div class="form-group">
            <div class="input-group">
                <input type="text" class="form-control flex-fill" placeholder="请输入后台管理地址，2000字以内" value="@Model.AdminPathBase" maxlength="2000" data-valid="true" />
                <ConditionComponent Inverse="true">
                    <div class="input-group-append">
                        <button class="btn btn-secondary" type="button" data-method="appPath">保存</button>
                    </div>
                </ConditionComponent>
            </div>
        </div>
    </div>
</div>
<div class="card" asp-auth="app">
    <div class="card-header">前台应用设置</div>
    <div class="card-body">
        <ConditionComponent>
            <div class="alert alert-danger" role="alert">
                <span>演示系统禁止更改前台应用设置</span>
            </div>
        </ConditionComponent>
        <div class="form-inline">
            <div class="row" id="appList">
                @foreach (var app in Model.Apps)
                {
                    <div class="form-group col-12 app" data-key="@app.Key">
                        <label class="control-label" for="@app.Key">@app.Name</label>
                        <div class="input-group flex-fill">
                            <input id="@app.Key" class="form-control" value="@app.Url" readonly />
                            <ConditionComponent Inverse="true">
                                <div class="input-group-append">
                                    <button class="btn btn-danger" type="button" data-key="@app.Key" data-method="delApp"><i class="fa fa-trash-o"></i><span>删除</span></button>
                                    <button class="btn btn-primary" type="button" data-key="@app.Key" data-method="editApp"><i class="fa fa fa-pencil"></i><span>编辑</span></button>
                                </div>
                            </ConditionComponent> 
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
    <ConditionComponent Inverse="true">
        <div class="card-footer text-right">
            <button class="btn btn-secondary" type="button" data-method="addApp"><i class="fa fa-plus"></i><span>新增</span></button>
        </div>
    </ConditionComponent>
</div>
<ConditionComponent AuthKey="saveTheme">
    <div class="card">
        <div class="card-header">网站样式设置</div>
        <div class="card-body">
            <div class="alert alert-info" role="alert">
                <span>注意：<b><a class="badge-pill" href="@("~/Admin/Profiles".ToBlazorMenuUrl())">个人中心</a></b>中设置的网站样式覆盖本设置</span>
            </div>
            <div class="form-group text-right">
                <div class="btn-group" role="group">
                    <div class="btn-group" role="group">
                        <button id="dictCssDefine" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="" value="@Model.Theme">默认样式</button>
                        <div class="dropdown-menu">
                            <a href="#" data-val="">默认样式</a>
                            @foreach (var css in Model.Themes)
                            {
                                <a href="#" data-val="@css.Code">@css.Name</a>
                            }
                        </div>
                    </div>
                    <button class="btn btn-secondary" type="button" data-method="css">保存</button>
                </div>
            </div>
        </div>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="saveUISettings">
    <div class="card">
        <div class="card-header">网站功能设置</div>
        <div class="card-body">
            <div class="form-inline">
                <div class="row">
                    <div class="form-group col-6">
                        <label class="control-label" for="sider">侧边栏设置</label>
                        <Toggle @bind-Value="@Model.ShowSideBar"></Toggle>
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="cardTitle">标题设置</label>
                        <Toggle @bind-Value="@Model.ShowCardTitle" OnText="显示" OffText="关闭"></Toggle>
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="cardTitle">固定表头</label>
                        <Toggle @bind-Value="@Model.FixedTableHeader" OnText="固定" OffText="跟随"></Toggle>
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="cardTitle">健康检查</label>
                        <Toggle @bind-Value="@Model.EnableHealth" OnText="开启" OffText="关闭"></Toggle>
                    </div>
                </div>
            </div>
        </div>
        <div class="card-footer text-right">
            <button class="btn btn-secondary" type="button" @onclick="SaveWebSettings"><i class="fa fa-save"></i><span>保存</span></button>
        </div>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="loginSettings">
    <div class="card" asp-auth="loginSettings">
        <div class="card-header">网站登录设置</div>
        <div class="card-body">
            <ConditionComponent>
                <div class="alert alert-danger" role="alert">
                    <span>演示系统禁止更改网站登录设置</span>
                </div>
            </ConditionComponent>
            <div class="form-inline">
                <div class="row">
                    <div class="form-group col-6">
                        <label class="control-label" for="mobile">手机登录</label>
                        <Toggle @bind-Value="@Model.ShowMobile" OnText="允许" OffText="关闭"></Toggle>
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="cardTitle">OAuth 认证</label>
                        <Toggle @bind-Value="@Model.ShowOAuth" OnText="允许" OffText="关闭"></Toggle>
                    </div>
                </div>
            </div>
        </div>
        <ConditionComponent Inverse="true">
            <div class="card-footer text-right">
                <button class="btn btn-secondary" type="button" @onclick="SaveLogin"><i class="fa fa-save"></i><span>保存</span></button>
            </div>
        </ConditionComponent>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="lockScreen">
    <div class="card">
        <div class="card-header">自动锁屏设置</div>
        <div class="card-body">
            <div class="form-inline">
                <div class="row">
                    <div class="form-group col-6">
                        <label class="control-label" for="lockScreen">自动锁屏</label>
                        <Toggle @bind-Value="@Model.AutoLockScreen" OnText="开启" OffText="关闭"></Toggle>
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="lockPeriod">时长间隔(秒)</label>
                        <input id="lockPeriod" type="number" class="form-control" @bind-value="@Model.LockScreenPeriod" />
                    </div>
                </div>
            </div>
        </div>
        <div class="card-footer text-right">
            <button class="btn btn-secondary" type="button"><i class="fa fa-save"></i><span>保存</span></button>
        </div>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="lockScreen">
    <div class="card" asp-auth="defaultApp">
        <div class="card-header">默认应用设置</div>
        <div class="card-body">
            <div class="alert alert-info" role="alert">
                <span>开启此功能后用户登录时默认导航到第一个已授权的前台应用</span>
            </div>
            <div class="form-inline">
                <div class="row">
                    <div class="form-group col-6">
                        <label class="control-label" for="defaultApp">默认应用</label>
                        <Toggle @bind-Value="@Model.DefaultApp" OnText="开启" OffText="关闭"></Toggle>
                    </div>
                </div>
            </div>
        </div>
        <div class="card-footer text-right">
            <button class="btn btn-secondary" type="button" @onclick="SaveDefaultApp"><i class="fa fa-save"></i><span>保存</span></button>
        </div>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="blazor">
    <div class="card">
        <div class="card-header">网站设置</div>
        <div class="card-body">
            <div class="alert alert-info" role="alert">
                <span>开启此功能网站增加 Blazor 与 MVC 切换挂件</span>
            </div>
            <div class="form-inline">
                <div class="row">
                    <div class="form-group col-6">
                        <label class="control-label" for="blazor">MVC 切换</label>
                        <Toggle @bind-Value="@Model.EnableBlazor" OnText="开启" OffText="关闭"></Toggle>
                    </div>
                </div>
            </div>
        </div>
        <div class="card-footer text-right">
            <button class="btn btn-secondary" type="button" @onclick="SaveBlazor"><i class="fa fa-save"></i><span>保存</span></button>
        </div>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="iplocate">
    <div class="card">
        <div class="card-header">地址位置信息</div>
        <div class="card-body">
            <ConditionComponent>
                <div class="alert alert-danger" role="alert">
                    <span>演示系统禁止更改地理信息配置</span>
                </div>
            </ConditionComponent>
            <div class="form-group">
                <Dropdown @bind-Value="@Model.SelectedIPLocator" Items="@Model.IPLocators"></Dropdown>
            </div>
        </div>
        <ConditionComponent Inverse="true">
            <div class="card-footer text-right">
                <button class="btn btn-secondary" type="button" @onclick="SaveIPLocator"><i class="fa fa-save"></i><span>保存</span></button>
            </div>
        </ConditionComponent>
    </div>
</ConditionComponent>
<ConditionComponent AuthKey="logSettings">
    <div class="card">
        <div class="card-header">地址位置信息</div>
        <div class="card-body">
            <ConditionComponent>
                <div class="alert alert-danger" role="alert">
                    <span>演示系统禁止更改日志缓存设置</span>
                </div>
            </ConditionComponent>
            <div class="form-inline">
                <div class="row">
                    <div class="form-group col-6">
                        <label class="control-label" for="appErrorLog">异常日志(月)</label>
                        <input id="appErrorLog" type="number" class="form-control" min="1" @bind-value="@Model.ErrorLogPeriod" />
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="opLog">操作日志(月)</label>
                        <input id="opLog" type="number" class="form-control" min="1" @bind-value="@Model.OpLog" />
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="logLog">登录日志(月)</label>
                        <input id="logLog" type="number" class="form-control" min="1" @bind-value="@Model.LogLog" />
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="traceLog">访问日志(月)</label>
                        <input id="traceLog" type="number" class="form-control" min="1" @bind-value="@Model.TraceLog" />
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="cookiePeriod">Cookie(天)</label>
                        <input id="cookiePeriod" type="number" class="form-control" min="1" @bind-value="@Model.CookiePeriod" />
                    </div>
                    <div class="form-group col-6">
                        <label class="control-label" for="ipCachePeriod">IP 缓存(分)</label>
                        <input id="ipCachePeriod" type="number" class="form-control" min="1" @bind-value="@Model.IPCachePeriod" />
                    </div>
                </div>
            </div>
        </div>
        <ConditionComponent Inverse="true">
            <div class="card-footer text-right">
                <button class="btn btn-secondary" type="button" @onclick="SaveLogSettings"><i class="fa fa-save"></i><span>保存</span></button>
            </div>
        </ConditionComponent>
    </div>
</ConditionComponent>
<div class="card" asp-auth="demo">
    <div class="card-header">演示系统设置</div>
    <div class="card-body">
        <div class="form-inline">
            <div class="row">
                <div class="form-group col-6">
                    <label class="control-label" data-toggle="lgbinfo" data-content="开启此功能网站切换至演示系统">演示系统</label>
                    <Toggle @bind-Value="@Model.EnableDemo" OnText="开启" OffText="关闭"></Toggle>
                </div>
                <div class="form-group col-6">
                    <label class="control-label" for="authKey">授权码</label>
                    <input type="password" autocomplete="off" class="form-control" @bind-value="@Model.AuthKey" />
                </div>
            </div>
        </div>
    </div>
    <div class="card-footer text-right">
        <button class="btn btn-secondary" type="button" @onclick="SaveSystemModel"><i class="fa fa-save"></i><span>保存</span></button>
    </div>
</div>
<div class="card">
    <div class="card-header">
        <span>网站缓存设置</span>
    </div>
    <div class="card-body">
        <Table Id="settings-cache" TItem="Longbow.Cache.ICacheItem" ShowToolBar="true" ShowRefresh="true" ShowExtendButtons="true" EditModel="ConsoleCaCheModel" OnQuery="QueryData">
            <TableHeader>
                <LgbTableHeader TItem="string" @bind-Value="@context.Desc"></LgbTableHeader>
                <LgbTableHeader TItem="int" @bind-Value="@context.Interval"></LgbTableHeader>
                <LgbTableHeader TItem="string" @bind-Value="@context.Key"></LgbTableHeader>
                <LgbTableHeader TItem="string" @bind-Value="@context.Value"></LgbTableHeader>
                <LgbTableHeader TItem="int" @bind-Value="@context.ElapsedSeconds"></LgbTableHeader>
            </TableHeader>
            <RowTemplate>
                <td>@context.Desc</td>
                <td>@(context.Interval / 1000)</td>
                <td>@context.Key</td>
                <td>@context.Value</td>
                <td>@context.ElapsedSeconds</td>
            </RowTemplate>
            <TableToolbarTemplate>
                <TableToolbarButton class="btn btn-danger" Icon="fa fa-trash-o" Title="一键清除" OnClick="ClearCache" />
            </TableToolbarTemplate>
            <ButtonTemplate>
                <button class='btn btn-sm btn-danger' asp-auth="del" @onclick="e => DeleteCache(context.Key)"><i class='fa fa-remove'></i><span>删除</span></button>
            </ButtonTemplate>
        </Table>
    </div>
</div>
